import logging
import pymysql


logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s: %(message)s',
                    datefmt='%a,%d %b %Y %H:%M:%S',
                    filename='dao.log',
                    filemode='a')

console = logging.StreamHandler()
console.setLevel(logging.WARNING)
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
console.setFormatter(formatter)
logging.getLogger("").addHandler(console)

mysql_conn = pymysql.connect(
    host='localhost',
    port=3306,
    user='root',
    password='x.1.2.3x',
    db='course_data',
    charset='utf8')
logging.debug("Connect to MySQL succeed: " + str(mysql_conn))
cursor = mysql_conn.cursor()